var app = getApp();
var baseUrl = app.globalData.host;
Page({
  onShow() {
    wx.reportAnalytics('enter_home_programmatically', {})
  },
  data: {
    list: [
    ],
    theme: 'light',
    custId:'',
    custName:'',
  },

  onLoad: function(option) {
    console.info(option.custName);
    console.info(option.custId);
    this.setData({
      theme: wx.getSystemInfoSync().theme || 'light',
      custId:option.custId,
      custName:option.custName,
    })
    if (wx.onThemeChange) {
      wx.onThemeChange(({ theme }) => {
        this.setData({ theme })
      })
    }
    var that = this;
    wx.request({
      url: baseUrl+"/report/selectTemplateMainList",
      method: 'POST',
      header: {
          'content-type': 'application/json'
      },
      dataType: 'json',
      success: function(res) {
        console.info(res);
        var lists = res.data.data
        for (let i = 0; i < lists.length; i++) {
          let pages = [];
          if(lists[i].templateCode === '01')
          {
            pages = [
              { zh: '农贷通调查报告', url: 'agriculturalLoan/notonginvereport/notonginvereport' },
              { zh: '种殖信息', url: 'agriculturalLoan/plant/plant' },
              { zh: '养殖信息', url: 'agriculturalLoan/breed/breed' },
              { zh: '非种养殖经营信息', url: 'agriculturalLoan/nonSeedCulture/nonSeedCulture' },
              { zh: '损益信息', url: 'agriculturalLoan/profitAndloss/profitAndloss' },
              { zh: '资产负载信息', url: 'agriculturalLoan/assetsLiabilities/assetsLiabilities' },
              { zh: '保证人信息', url: 'agriculturalLoan/guarantorInfo/guarantorInfo' },
              { zh: '其他人评价信息', url: 'agriculturalLoan/evaluate/evaluate' },
              { zh: '调查结论及建议', url: 'agriculturalLoan/conclusionProposal/conclusionProposal' }
            ]
          }
          if(lists[i].templateCode === '06')
          {
            pages = [
              { zh: '生产加工行业调查报告', url: 'amountMachining/processTrade/processTrade' },
              { zh: '基本信息', url: 'amountMachining/basicInformation/basicInformation' },
              { zh: '生产加工信息', url: 'amountMachining/productionMachining/productionMachining' },
              { zh: '资产负债信息', url: 'amountMachining/assetsLiabilities/assetsLiabilities' },
              { zh: '特色行业问题', url: 'amountMachining/IndustryIssues/IndustryIssues' },
              { zh: '调查结论及建议', url: 'amountMachining/conclusionSuggestion/conclusionSuggestion' }
            ]
          }
          if(lists[i].templateCode === '07')
          {
            pages = [
              { zh: '收购行业调查报告', url: 'acquisition/acquisitionIndustry/acquisitionIndustry' },
              { zh: '基本信息', url: 'acquisition/basicInformation/basicInformation' },
              { zh: '收购信息', url: 'acquisition/acquisitionInformation/acquisitionInformation' },
              { zh: '资产负债信息', url: 'pagination/pagination' },
              { zh: '担保信息特色行业问题', url: 'freelayout/freelayout' },
              { zh: '调查结论及建议', url: 'layeredpresentation/layeredpresentation' }
            ]
          }
          if(lists[i].templateCode === '03')
          {
            pages = [
              { zh: '基本信息', url: 'plant/plant' },
              { zh: '种植信息', url: 'breed/breed' },
              { zh: '养殖信息', url: 'pagination/pagination' },
              { zh: '商业经营信息', url: 'freelayout/freelayout' },
              { zh: '损益及资产负债信息', url: 'layeredpresentation/layeredpresentation' },
              { zh: '担保情况-担保方式', url: 'layeredpresentation/layeredpresentation' },
              { zh: '其他人评价信息', url: 'layeredpresentation/layeredpresentation' },
              { zh: '调查结论及建议', url: 'layeredpresentation/layeredpresentation' }
            ]
          }
          if(lists[i].templateCode === '02')
          {
            pages = [
              { zh: '商贷通调查报告', url: 'plant/plant' },
              { zh: '信贷员尽职声明', url: 'breed/breed' }
            ]
          }
          that.setData({
            [`list[${[i]}].id`]: lists[i].templateCode,
            [`list[${[i]}].name`]: lists[i].templateName,
            [`list[${[i]}].open`]: false,
            [`list[${[i]}].pages`]:pages,
          })
        }
        console.info(that.data.list);
      },
      fail: function(res) {
          wx.showToast({
          title: '服务器网络错误,请稍后重试',
          icon: 'loading',
          duration: 1500
          })
      },
      complete: function(res) {
        if(res.statusCode === 500){
          wx.showModal({
            title: '提示',
            showCancel: false,
            content: '后台查询，请查看！',
            success: function () {
              wx.navigateBack({ //跳转到前一个页面
                delta:1,//前一个页面
              });
            }
          })
        }
      },
    })
  },

  kindToggle(e) {
    const id = e.currentTarget.id
    const list = this.data.list
    for (let i = 0, len = list.length; i < len; ++i) {
      if (list[i].id === id) {
        list[i].open = !list[i].open
      } else {
        list[i].open = false
      }
    }
    this.setData({
      list
    })
    wx.reportAnalytics('click_view_programmatically', {})
  }
})
